﻿using Sys.Model;
using Sys.Core.Tour;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sys.Common;
using System.Text.RegularExpressions;

public partial class Scenic : System.Web.UI.Page
{
    public TourScenic model { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["id"];

            if (!string.IsNullOrEmpty(id))
            {
                model = ScenicBll.I.GetByKey(id);

                if (model != null)
                {
                    Home mas = Master as Home;

                    string des = StringHelper.NoHTML(model.Content);

                    mas.SetHead(model.Name, model.Name, StringHelper.CutString(des, 100));

                    #region Cookie

                    HttpCookie cookie = Request.Cookies["Scenic"];

                    string cookies = model.ID;

                    if (cookie != null)
                    {
                        if (!cookie.Value.Contains(cookies))
                        {
                            cookies = cookies + "," + cookie.Value;

                            if (Regex.Matches(cookies, @",").Count > 3)
                            {
                                cookies = cookies.Substring(0, cookies.LastIndexOf(","));
                            }
                        }
                        else
                        {
                            cookies = cookies + "," + cookie.Value.Replace(cookies, string.Empty).Replace(",,", ",").TrimEnd(',');
                        }

                        cookie.Value = cookies;
                    }
                    else { cookie = new HttpCookie("Scenic", cookies); }

                    Response.Cookies.Add(cookie);

                    #endregion
                }
                else { model = new TourScenic(); }
            }
            else { model = new TourScenic(); }
        }
    }
}